<template>
    <page class="pb60">
        <m-header>确认订单</m-header>
        <div v-for="i in list" class="white-bg item pr12 mt10" flex="box:first">
            <m-img :src="i.image" ratio="1" class="img"/>
            <div class="ml16 my16" flex="dir:top box:justify">
                <p class="f18">{{i.title}}</p>
                <p class="f14 text3 mt6"></p>
                <div class="f14" flex="main:justify">
                    <div>{{i.price}}积分<span class="text3 ml6">x{{i.number}}</span></div>
                    <div class="c7">{{i.price * i.number}}积分</div>
                </div>
            </div>
        </div>
        <nav class="tr white-bg f16 fix posbl fitw shadow" flex="main:right cross:center">
            <span>共</span>
            <span class="c1">{{list.length}}</span>件，合计&nbsp;
            <span class="red fmd">{{order.payMoney}}</span>
            <span class="bg1 white px20 tap ml10 h50" style="display: inline-block" @click="submit">提交订单</span>
        </nav>
    </page>
</template>
<script>
  export default {
    data () {
      const {id} = this.$route.query
      return {
        id,
        shopName: null,
        order: {},
        list: [],
        form: {
          id
        }
      }
    },
    computed: {
      PitsForm () {
        const {list, order, id} = this
        return {
          list,
          order: {
            ...order,
            id,
            createDate:new Date(), // stupid backend
            payTime: new Date() // stupid backend
          }
        }
      }
    },
    async created () {
      let body = await this.$get('order/getOrder/' + this.id)
      let {deTailList, order} = body.obj
      this.list = deTailList
      this.order = order
      let body2 = await  this.$get('company/getShopById', {shopId: order.shopId})
      this.shopName = body2.obj.shopName
    },
    methods: {
      PitsPullData () {},
      PitsPushData () {},
      // 提交订单
      async submit () {
        let body = await this.$post_json_loading('order/addOrder', this.PitsForm)
        if (body.code != 200) {
          console.error('提交失败')
          return
        }
        let data = await this.$post_loading('order/payOrderById', {
          orderId: this.id
        })
        if (data.obj != true) {
          console.error('提交失败')
          return
        }
        this.$store.dispatch('updateUserInfo')
        this.$router.replace({name: 'store_qr', query: {id: this.id}})
      }
    },
    components: {}
  }
</script>
<style type="text/scss" lang="scss" scoped>
    $h: 120px;
    .item {
        height: $h;
        .img {
            width: $h;
        }
    }
</style>
